<%@page import="com.printeverywhere.dto.BannerCampaigns"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="display" uri="http://displaytag.sf.net"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<s:form method="post" theme="simple">
<table width="100%">
	<tr>
		<td height="40" colspan="2" class="sectionheading bottom-border">
			<s:text name="manageCampaign.header" />
		</td>
	</tr>
	<tr>
		<td height="8">
		</td>
	</tr>
	<tr>
		<td>
			<s:actionerror cssClass="Note-red" />
			<s:actionmessage cssClass="verdana11greynormal" />
		</td>
	</tr>
	<tr>
		<td>
				<tr align="left">
				<td>
			<table>
			<tr>
					<td class="verdana12blacknormal" align="right">
						<s:text name="Show Status:" />
					</td>
					<td align="left">
						<s:select cssClass="textfiled-border" name="status"
							list="#{'0':'All','1':'pending','3':'rejected','5':'approved','2':'active','4':'suspended','6':'expired'}"
							theme="simple"></s:select>
					</td>
				</tr>
				<tr align="left">
					<td class="verdana12blacknormal" align="right">
						<s:text name="manageCampaign.bannerType" />
					</td>
					<td align="left">
						<s:select cssClass="textfiled-border" listKey="id" listValue="formatName"
							headerKey="0" headerValue="All" list="bannerType" name="bannerTypeId"
							theme="simple" value="%{bannerTypeId}"></s:select>
					</td>
				</tr>
				<tr align="left">
					<td class="verdana12blacknormal" align="right">
						<s:text name="manageCampaign.category" />
					</td>
					<td align="left" class="verdana12blacknormal">
						<div id="selectedCatId">
							<s:if test="%{bannerCampaigns.categories != null}">
								<s:iterator value="bannerCampaigns.categories" var="categories"
									status="status">
									<s:property value="%{bannerCampaigns.categories[#status.index]}" />
									<s:if test="#status.last == false">-></s:if>
								</s:iterator>
							</s:if>
							<s:else>
								<s:text name="addSellAuctionItem.category.msg" />
							</s:else>
						</div>
						<input type="button" onclick="PPPCC=window.open('<%= basePath + "ajax/showCategoryTreeAction.htm" %>','CurrencyConverter','width=600,height=400,scrollbars=yes,resizable=false');PPPCC.focus()" name="Select Category" value="Select Category" class="submit-btn-common" />
					</td>
				</tr>
				<tr align="left">
					<td class="verdana12blacknormal" align="right">
						<s:text name="manageCampaign.user" />
					</td>
					<td align="left">
						<s:textfield name="userId" value="%{userId}" theme="simple" cssClass="textfiled-border" />
					</td>
				</tr>
				<tr align="left">
					<td align="right">
						<s:submit value="show" action="findManageCampaigns" />
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<s:set var="pageSize" value="pageSize" />
			<display:table name="banners" pagesize="${pageSize}" cellpadding="0" cellspacing="0" requestURI="showManageCampaigns.htm" id="row" class="verdana12blacknormal">
				<display:column headerClass="Table-Head" title="User" property="user.userId" />
				<display:column headerClass="Table-Head" title="Campain Name" property="campaign" />
				<display:column headerClass="Table-Head" title="Start date" property="startDate" />
				<display:column headerClass="Table-Head" title="No. of views" value="0" />
				<display:column headerClass="Table-Head" title="No. of clicks" property="maxClicks" />
				<display:column headerClass="Table-Head" title="Status">
					<%
						int status = ((BannerCampaigns) row).getStatus();
						if(status == 1)
							out.print("Pending");
						else if(status == 2)
							out.print("Active");
						else if(status == 3)
							out.print("Rejected");
						else if(status == 4)
							out.print("Suspend");
						else if(status == 5)
							out.print("Approved");
						else if(status == 6)
							out.print("Expired");
					%>
				</display:column>
				<display:column headerClass="Table-Head" title="Categories" >
					<s:iterator value="#attr.row.categories" status="row">
						<s:property />
					</s:iterator>
				</display:column>
				<display:column headerClass="Table-Head" title="Banner Type" property="bannerSettings.formatName" />
				<display:column headerClass="Table-Head" title="Campaign Type" value="Views" />
				<display:column headerClass="Table-Head" title="Purchased" value="1000" />
				<display:column headerClass="Table-Head" title="Spent" value="800" />
				<display:column headerClass="Table-Head" title="Action">
					<table>
						<tr>
							<td id="mddm" valign="top" rowspan="2" class="verdana12blacknormal">
								<a class="navi-link" href="#" onmouseover="mopen('<%= row_rowNum %>', this, 'navi-link', 'right', <%= row_rowNum %>)" onmouseout="mclosetime()"><s:text name="manageCampaign.select" /></a>
								<div style="visibility: hidden;" id="<%= row_rowNum %>" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
									<s:if test="#attr.row.status == 4">
										<a href="approveManageCampaigns.htm?id=<%= ((BannerCampaigns) row).getId() %>&pageSize=${pageSize}"><s:text name="Enable" /></a>
									</s:if>
									<s:else>
										<a href="suspendManageCampaigns.htm?id=<%= ((BannerCampaigns) row).getId() %>&pageSize=${pageSize}"><s:text name="manageCampaign.suspend" /></a>
									</s:else>
									<a href="javascript: wantToDeleteWithURL('deleteManageCampaigns.htm?id=<%= ((BannerCampaigns) row).getId() %>&pageSize=${pageSize}','Do you want to delete this Campaign?')"><s:text name="manageCampaign.delete" /></a>
									<a href="mailto: <%= ((BannerCampaigns) row).getUser().getEmail() %>">Contact</a>
									<a href="showCampaignsStatus.htm?id=<%= ((BannerCampaigns) row).getId() %>&pageSize=${pageSize}"><s:text name="manageCampaign.status" /> </a>
								</div>
							</td>
						</tr>
					</table>
				</display:column>
				<display:column>
					<tr>
						<td colspan="12" class="" bgcolor="<%= row_rowNum % 2 == 0 ? "#F8F8F8" : "" %>">
							<s:if test="#attr.row.image != null && #attr.row.image !=''">
								<img src="../servlet/ImageServlet?dto=BannerCampaigns&id=<s:property value="#attr.row.id"/>" alt="alttext" border="0" style="margin: 5px 0px 0px 5px">
							</s:if>
							<s:else><img src="<%= request.getContextPath() %>/images/no_image.gif" alt="No Image" height="45" width="45"/></s:else>
						</td>
					</tr>
				</display:column>
			</display:table>
		</td>
	</tr>
	<tr>
		<td>
			<table>
				<tr>
					<td class="verdana12blacknormal">
						<s:text name="manageCampaign.campaignsperpage" />
					</td>
					<td>
						<s:select cssClass="textfiled-border" onchange="document.forms[0].submit();"
							name="pageSize" list="#{'10':'10','20':'20','50':'50','100':'100'}" theme="simple"></s:select>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</s:form>